body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    max-height: 60vh;
    margin: 0;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    transition: all 0.3s;
}
button:hover {
    background-color: #45a049;
    transform: scale(1.05);
}
button:active {
    transform: scale(0.95);
}

#requestDeviceMotionPermission {
    visibility:hidden;
    margin: 0px;
    font-size: small; 
}

.dice-container {
    margin: 30px 10px 50px 10px;
    padding-bottom: 150px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    
}
.dice {
    width: var(--dice-size, 200px);
    height: var(--dice-size, 200px);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s ease;
    font-size: calc(var(--dice-size, 200px) * 0.5);
    margin: calc(var(--dice-size, 200px) * 0.1);
}
.face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-width: min(max(2px, calc(var(--dice-size, 200px) * 0.02)), 4px);
    border-style: solid;
    border-color: #333;
    border-radius: 10%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    background-color: white;
}
.face-1 { transform: translateZ(calc(var(--dice-size, 200px) / 2)); }
.face-2 { transform: rotateY(180deg) translateZ(calc(var(--dice-size, 200px) / 2)); }
.face-3 { transform: rotateY(90deg) translateZ(calc(var(--dice-size, 200px) / 2)); }
.face-4 { transform: rotateY(-90deg) translateZ(calc(var(--dice-size, 200px) / 2)); }
.face-5 { transform: rotateX(90deg) translateZ(calc(var(--dice-size, 200px) / 2)); }
.face-6 { transform: rotateX(-90deg) translateZ(calc(var(--dice-size, 200px) / 2)); }
.dot {
    width: 20%;
    height: 20%;
    background-color: black;
    border-radius: 50%;
    position: absolute;
}
.stats {
    background: #f8f9fa;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-top: 20px;
    max-height: none;
    overflow-y: visible;
    width: 100%;
}
.result-item {
    display: inline-block;
    padding: 3px 8px;
    margin: 3px;
    background: #e9ecef;
    border-radius: 4px;
    animation: fadeIn 0.5s;
    font-size: 0.9em;
    line-height: 1.2;
}
.stats h2 {
    margin: 5px 0 10px 0;
    font-size: 1.2em;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
#total {
    font-weight: bold;
    color: #4CAF50;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

#history {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: #ffffff;
    border-top: 1px solid rgba(0,0,0,0.1);
    border-radius: 16px 16px 0 0;
    transition: all 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    overflow: hidden;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
    z-index: 5;
    /* translateZ fix safari z-index */
    transform: translateY(calc(100% - 60px)) translateZ(1005px);
    will-change: transform;
}
#history.visible {
    transform: translateY(0) translateZ(1005px);
}
#history.visible-more {
    height: 160px;
    transform: translateY(0) translateZ(1005px);
}
#history.expanded {
    height: 60vh;
    transform: translateY(0) translateZ(1005px);
}
#history h2 {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 16px 20px 8px;
    margin: 0;
    background: white;
    font-size: 1.1em;
    font-weight: 500;
    color: #333;
}
#history h2 span#total {
    justify-self: start;
}
.history-right-group {
    display: none;
    justify-self: end;
    margin-left: auto;
}
.throw-count {
    font-size: 0.9em;
}
.clear-history {
    display: none;
    background: none;
    border: none;
    color: #007AFF;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    justify-self: end;
    margin-left: auto;
}
#history h2:active {
    background-color: #f5f5f5;
}
#historyList {
    padding: 0px 20px 8px;
    max-height: calc(60vh - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#historyList::-webkit-scrollbar {
    display: none;
}
.history-item {
    padding: 6px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    animation: fadeIn 0.3s;
}
.history-info {
    padding: 6px 0;
    text-align: center;
    font-size: small;
    font-style: italic;
    color: #888;
}
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(0,-80%);
    }
    to {
        opacity: 1;
        transform: translate(0,0);
    }
}
.history-item.insert-animation {
    animation: slideIn 0.4s ease-out;
}
.history-icon {
    display: none;
    justify-self: center;
    width: 36px;
    height: 36px;
    transition: transform 0.3s ease, stroke 0.3s ease;
    margin-left: 8px;
    stroke: #4CAF50;
    stroke-width: 3.5;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
}
.history-icon:hover {
    stroke: #45a049;
    transform: scale(1.2);
    filter: drop-shadow(0 3px 5px rgba(0,0,0,0.3));
}
.history-icon.up {
    transform: rotate(180deg);
}
@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}
.history-icon.prompt {
    animation: bounce 1.5s infinite;
}
#history.no-transition {
    transition: none;
}

.fullscreen-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 10;
    -webkit-transform: translateZ(1010px);
    padding: 10px;
    cursor: pointer;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}
.fullscreen-btn:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}
.fullscreen-btn:active {
    transform: scale(0.95);
}
.fullscreen-btn svg {
    width: 40px;
    height: 40px;
    stroke: #4CAF50;
    stroke-width: 2;
    transition: all 0.3s ease;
}
#exitFullscreen {
    display: none;
}

.menu-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 10;
    -webkit-transform: translateZ(1010px);
    width: 30px;
    height: 20px;
    padding: 30px 30px 40px 40px;
    cursor: pointer;
}
.menu-btn span {
    display: block;
    width: 100%;
    height: 3px;
    background: #4CAF50;
    margin: 5px 0;
    transition: all 0.3s;
}
.menu-container {
    position: fixed;
    top: 0;
    right: -350px;
    width: 300px;
    height: 100%;
    background: white;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    transition: right 0.3s;
    z-index: 9;
    -webkit-transform: translateZ(1009px);
    padding: 20px;
    overflow-y: auto;
}
.menu-container.active {
    right: 0;
}
.menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.menu-btn.active span:nth-child(2) {
    opacity: 0;
}
.menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* 去掉 input 输入框里的小三角 */
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}
input[type="number"]
{
    -moz-appearance: textfield;    
}

.controls {
    background: white;
}
.control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
}
.input-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}
.controls input[type="number"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 2em
}      
.number-wrapper {
    display: flex;
    align-items: center;
}
.number-btn {
    width: 30px;
    padding: 2px;
    margin: 0px 4px;
    font-size: 24px;
}
.dice-size-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
#diceSizeValue {
    cursor: pointer; 
    border: 1px dashed #ccc; 
    padding: 2px;
    margin: 0px 2px 0px 5px;
}

#diceSizeFloating {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 150px;
    z-index: 100;
    -webkit-transform: translateZ(1100px);
    opacity: 1 !important;
}
.slider-value {
    position: fixed;
    top: -25px;
    left: 0;
    z-index: 101;
    /* translateZ fix safari z-index */
    transform: translateX(-50%) translateZ(1101px); 
    background: #4CAF50;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    display: none;
}
.slider-value::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #4CAF50;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 150px;
    height: 8px;
    border-radius: 5px;
    background: #ccc;
    outline: none;
    /* 轨道划过效果 */
    background: linear-gradient(to right, #4CAF50 0%, #4CAF50 60%, #ccc 60%, #ccc 100%);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #4CAF50;
    cursor: pointer;
    border: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
    margin: 10px 15px;
}
.switch-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
}
.switch-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

#debugSwitchWrapper {
    display: none;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: #4CAF50;
}
input:checked + .slider:before {
    transform: translateX(26px);
}

.about-section {
    position: sticky;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: end;
    padding: 20px 0;
    margin: 0;
    color: #666;
    font-size: 14px;
    z-index: -1;
}
@media (min-height: 700px) {
    .about-section {
        position: absolute;
        bottom: 40px;
        padding: 20px;
    }
}

#about {
    cursor: pointer;
}